<?php
include_once ('Include/init.php');
$test = $_GET['urls'];
$urls = isset($_GET['urls']) ? trim($_GET['urls'], '/') : 'Index/Index';
if (isset($_GET['urls'])) unset($_GET['urls']);


$params = split('/', $urls);
//处理get
$count = count($params);
/*
 * 意思自己看
if(ucfirst($params[0])!='Admin' && ucfirst($params[0])!='My' && ucfirst($params[0])!='Page'){
	array_unshift($params, 'Page');
}

$appName = ucfirst(isset($params[0]) ? $params[0] : 'Page');
$ctrName = ucfirst(isset($params[1]) ? $params[1] : 'Index');
$mtdName = isset($params[2]) ? $params[2] : 'Show';
*/

$appName = ucfirst(isset($params[0]) ? $params[0] : 'Index');
$ctrName = ucfirst(isset($params[1]) ? $params[1] : 'Index');
$mtdName = isset($params[2]) ? $params[2] : 'oauth';

if ($count > 2){
	for ($i=3; $i<$count; $i+2){
		$_GET[$params[$i]] = isset($params[$i+1]) ? $params[$i+1] : '';
	}
}
define('APP_NAME', $appName);
$filename = ROOT_DIR . "Controllers/{$appName}/{$ctrName}.php";
/*
if (!file_exists($filename)){
	exit('Page Not Found! From Index');
}
*/

require_once $filename;

$ctrIst = new $ctrName();

$ctrIst->$mtdName();

//自动加载文件
function __autoload($classname)
{
	$findPath = array(
		ROOT_DIR . 'Libraries/' . $classname . '.php',
		ROOT_DIR . 'Controllers/' . APP_NAME . '/' . $classname . '.php',
		ROOT_DIR . 'Modules/' . $classname . '.php',
	);
	
	foreach ($findPath as $filename){
		if (file_exists($filename)){
			require_once $filename;
			return true;
		}
	}
	
	return false;
}